<?php
namespace app\modules\admin\forms\activity;

use app\common\forms\BaseForm;
use Carbon\Carbon;

class ActivityForm extends BaseForm{

    public $act_id;
    public $merchant_id;
    public $act_name;
    public $type;
    public $min_amount;
    public $content;
    public $start_time;
    public $end_time;

    public function scenarios()
    {
        return [
            'create'=>[
                'merchant_id','act_name','type','min_amount','content','start_time','end_time',
            ],
            'update'=>[
                'act_id','merchant_id','act_name','type','min_amount','content','start_time','end_time',
            ],
        ];
    }

    public function rules()
    {
        return [
            ['act_id','required','on'=>['update'],'message'=>\Yii::t("app","活动ID不能为空")],
            ['merchant_id','required','on'=>['create','update'],'message'=>\Yii::t("app","商户ID不能为空")],
            ['act_name','required','on'=>['create','update'],'message'=>\Yii::t("app","活动ID不能为空")],
            ['type','integer','skipOnEmpty'=>false,'on'=>['create','update'],'message'=>\Yii::t("app","类型错误")],
            ['min_amount','number','skipOnEmpty'=>false,'on'=>['create','update'],'message'=>\Yii::t("app","最小金额错误")],
            ['content','number','skipOnEmpty'=>false,'on'=>['create','update'],'message'=>\Yii::t("app","优惠值错误")],
            ['start_time','required','on'=>['create','update'],'message'=>\Yii::t("app","开始时间不能为空")],
            ['end_time','required','on'=>['create','update'],'message'=>\Yii::t("app","结束时间不能为空")],
            ['start_time','date','on'=>['create','update'],'skipOnEmpty'=>false,'format'=>'yyyy-MM-dd','min'=>Carbon::now()->toDateString(),'tooSmall'=>\Yii::t("app","开始日期不能小于今天"),'message'=>\Yii::t("app","开始时间格式错误")],
            ['end_time','date','on'=>['create','update'],'skipOnEmpty'=>false,'format'=>'yyyy-MM-dd','min'=>$this->start_time,'tooSmall'=>\Yii::t("app","结束日期不能小于开始日期"),'message'=>\Yii::t("app","结束时间格式错误")],
        ];
    }
}